package com.ksyun.alert.result;

import lombok.Data;

import java.io.Serializable;

/**
 * 统一返回对象
 * @author Zhang
 * @date 2024-04-30
 */
@Data
public class RestResult<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 异常信息
     */
    private String Message;

    private Integer code;

    private String requestId;

    /**
     * 成功的返回
     * @param requestId 请求id
     * @param <T> 返回data类型
     */
    public static <T> RestResult<T> success(String requestId) {
        RestResult<T> result = new RestResult<>();
        result.Message = "ok";
        result.requestId = requestId;
        result.code = 200;
        return result;
    }

    /**
     * 错误的返回
     * @param Message 返回消息
     * @param <T> 返回data类型
     * 错误返回数据，暂定为错误信息自定义，requestId为null
     */
    public static <T> RestResult<T> error(String Message) {
        RestResult<T> result = new RestResult<>();
        result.Message = Message;
        result.requestId = null;
        result.code = 400;
        return result;
    }
}

